﻿using System;
using System.Collections.Generic;
using System.Linq;
using LeadTracker.Models;

namespace LeadTrackerMVC.Models
{
	public class DashboardModel
	{
		public DashboardModel(int userKey, LeadCollection activeLeads, EditorCollection editors)
		{
			if (activeLeads == null)
				throw new ArgumentNullException("activeLeads", "activeLeads is null.");
			if (editors == null)
				throw new ArgumentNullException("editors", "editors is null.");
			
			m_Editors = editors;
			foreach (var item in activeLeads)
			{
				if (item.OwnerKey == userKey)
					YourLeads.Add(item);
				else
					OtherActiveLeads.Add(item);
			}
		}

		readonly EditorCollection m_Editors;
		readonly LeadCollection m_YourLeads = new LeadCollection();
		readonly LeadCollection m_OtherActiveLeads = new LeadCollection();

		public LeadCollection YourLeads
		{
			get { return m_YourLeads; }
		}

		public LeadCollection OtherActiveLeads
		{
			get { return m_OtherActiveLeads; }
		}

		public string EditorName(int? editorKey)
		{
			if (editorKey == null)
				return "";

			if (m_Editors.Contains(editorKey.Value))
				return m_Editors[editorKey.Value].FullName;
			return "";
		}


	}
}